package tests.update;

import static org.junit.Assert.*;

import model.Budget;
import model.BudgetFactory;
import model.Line;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

public class LineUpdateIdTest00
{
	Budget budget;
	Line line;
	Line subline;
	BudgetFactory factory;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
		Helper.delete(subline, WorkletContext.getInstance());
		Helper.delete(line, WorkletContext.getInstance());
		Helper.delete(budget, WorkletContext.getInstance());
	}

	@Test
	public void test()
	{
		factory = new BudgetFactory();
        
	 	 try
		 {
	 
			  //Create a budget
		        budget = (Budget) factory.create();
	            budget.setName("Test budget");
	            
	            budget.setDescription("This is an update test budget.");
	            
	            line = (Line) budget.createLine();
	            
	            budget.commit();
	            
	            Line lines = (Line) Helper.fetch("Lines", 100, WorkletContext.getInstance());
				lines.setId(90);
				Helper.insert(lines, WorkletContext.getInstance());

	            Boolean successful = budget.commit();

            
            if(!successful)
            	fail("Line failed to update");
            
        }
        catch(Exception e) {
            fail("Creating Budget failed with exception: " + e);
        }

}
}
